using System;

namespace ObjectSerializers.Abstractions
{
    public abstract class SerializerException : Exception
    {
        /// <summary>
        /// 序列化程序名称
        /// </summary>
        public string SerializerTypeName { get; }

        /// <summary>
        /// 类型名称
        /// </summary>
        public string TypeName { get; }

        public SerializerException(string typeName, string serializerTypeName)
        {
            this.TypeName = typeName;
            this.SerializerTypeName = serializerTypeName;
        }
    }

    /// <summary>
    /// 序列化异常
    /// </summary>
    public class SerializeException : SerializerException
    {
        /// <summary>
        /// 类型值
        /// </summary>
        public object TypeValue { get; }


        public SerializeException(string typeName, object typeValue, string serializerTypeName)
            : base(typeName, serializerTypeName)
        {
            this.TypeValue = typeValue;
        }
    }

    /// <summary>
    /// 反序列化异常
    /// </summary>
    public class DeserializeException : SerializerException
    {
        public ReadOnlyMemory<byte> Buffer { get; }

        public DeserializeException(string typeName, ReadOnlyMemory<byte> buffer, string serializerTypeName)
            : base(typeName, serializerTypeName)
        {
            this.Buffer = buffer;
        }
    }
}